{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ufw\n",
    "\n",
    "## 安装方法\n",
    "\n",
    "```sh\n",
    "sudo apt-get install ufw\n",
    "```\n",
    "\n",
    "当然，这是有图形界面的 (比较简陋)，在新立得里搜索 gufw 试试……\n",
    "\n",
    "## 使用方法\n",
    "\n",
    "1. 启用\n",
    "\n",
    "```sh\n",
    "sudo ufw enable\n",
    "sudo ufw default deny\n",
    "```\n",
    "\n",
    "**作用**：开启了防火墙并随系统启动同时关闭所有外部对本机的访问（本机访问外部正常）。\n",
    "\n",
    "2 关闭\n",
    "\n",
    "```sh\n",
    "sudo ufw disable\n",
    "```\n",
    "\n",
    "2 查看防火墙状态\n",
    "\n",
    "```sh\n",
    "sudo ufw status\n",
    "```\n",
    "\n",
    "3 开启 / 禁用相应端口或服务举例\n",
    "\n",
    "```sh\n",
    "sudo ufw allow 80 允许外部访问80端口\n",
    "\n",
    "sudo ufw delete allow 80 禁止（删除）外部访问80 端口\n",
    "\n",
    "sudo ufw allow from 192.168.1.1 允许此IP访问所有的本机端口\n",
    "\n",
    "sudo ufw deny smtp 禁止外部访问smtp服务\n",
    "\n",
    "sudo ufw delete allow smtp 删除上面建立的某条规则\n",
    "\n",
    "sudo ufw deny proto tcp from 10.0.0.0/8 to 192.168.0.1 port 22 要拒绝所有的TCP流量从10.0.0.0/8 到192.168.0.1地址的22端口\n",
    "\n",
    "可以允许所有RFC1918网络（局域网/无线局域网的）访问这个主机（/8,/16,/12是一种网络分级）：\n",
    "sudo ufw allow from 10.0.0.0/8\n",
    "sudo ufw allow from 172.16.0.0/12\n",
    "sudo ufw allow from 192.168.0.0/16\n",
    "```\n",
    "\n",
    "推荐设置\n",
    "----\n",
    "\n",
    "```sh\n",
    "sudo apt-get install ufw\n",
    "\n",
    " sudo ufw enable\n",
    "\n",
    " sudo ufw default deny\n",
    "```\n",
    "\n",
    "这样设置已经很安全，如果有特殊需要，可以使用 sudo ufw allow 开启相应服务。\n",
    "\n",
    "[img-0]:http://common.cnblogs.com/images/copycode.gifjavascript:void0\n",
    "\n",
    "[img-1]:data:"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
